package top.akame.webs.controller

import org.springframework.stereotype.Controller
import org.springframework.ui.ModelMap
import org.springframework.util.Base64Utils
import org.springframework.web.bind.annotation.GetMapping
import javax.servlet.http.HttpServletRequest

@Controller
class ViewController {

    @GetMapping("", "/", "/index")
    fun index(f: String?, model: ModelMap, request: HttpServletRequest): String {
        val url = request.requestURL
        val host = url.substring(0, url.lastIndexOf("/"))
        val m3u8 = String(Base64Utils.decodeFromUrlSafeString(f.orEmpty()))
        model["m3u8"] = "$host/v1/$m3u8/index.m3u8"
        model["cover"] = "$host/v1/$m3u8/cover.png"
        return "index"
    }

    @GetMapping("/up")
    fun uploadView(): String {
        return "upload"
    }

}
